﻿#include "osgi-predefined.h"
#include "IService.h"


namespace MicroKernelRuntime
{


#define LEVEL_EXCHANGE_HIGH				1
#define LEVEL_EXCHANGE_GENERAL                          2
#define LEVEL_EXCHANGE_LOW				3

//errCodes
#define RPC_CALL_OK					0
#define RPC_TRANSMIT_FAILED				1
#define RPC_NOHANDLER_REGISTERED                        2
#define RPC_DATA_CORRUPTED				3


//OSGI_INTERFACE IMemBufReader //
//{
//        virtual const void* OSGI_API GetBuf() = 0;
//        virtual int OSGI_API GetLength() = 0;
//        virtual void OSGI_API Destroy() = 0;
//};

OSGI_INTERFACE IInvokeMsgHandler
{
public:
        virtual void OSGI_API OnMsgCall(
		char* msgType, 
		int serializeMode,
		IMemBufReader* msgContent,/*msgContent should be free by handler*/
		IDictionary* invokeContext) = 0;/*invokeContext should be free by handler*/
};

#define IID_RPC_Server "IID_RPC_Server"
#define SID_RPC_Server "SID_RPC_Server"
OSGI_INTERFACE IRPCService : public IService
{
public:
	//RPC调用结果发送接口
        virtual int OSGI_API PostInvokeRes(
			IMemBufReader* resMsgContent, /*resMsgContent should be free by caller*/
			int invokeResCode,
			IDictionary* invokeContext) = 0;/*方法调用上下文，须传递IInvokeMsgHandler*/
											/*的invokeContext 参数，确保调用唯一性*/
											/*invokeContext should be free by caller*/

	//同步/异步RPC调用消息订阅接口
        virtual int OSGI_API RegisterInvokeMsgHandler(
			const char* msgType, 
			IInvokeMsgHandler* pHandler, 
			const char* serviceName) = 0;

        virtual int OSGI_API UnRegisterInvokeMsgHandler(
			const char* msgType, 
			IInvokeMsgHandler* pHandler, 
			const char* serviceName = NULL) = 0;
};



OSGI_INTERFACE IInvokeResMsgHandler
{
public:
        virtual void OSGI_API OnMsgRes(
		IMemBufReader* msgResContent,
		int invokeResCode
		) = 0;
};


#define IID_RPC_Client "IID_RPC_Client"
#define SID_RPC_Client "SID_RPC_Client"
OSGI_INTERFACE IRPCClient : public IService
{
        //同步RPC调用接口，返回invokeResCode
        virtual int OSGI_API SynInvoke(
			char* msgType,
			int serializeMode, /*序列化方式*/
                        IMemBufReader* reqMsgContent, /*reqMsgContent should be free by caller*/
                        IMemBufReader** resMsgContent, /*resMsgContent should be free by caller*/
			const char* serviceName, 
			IDictionary* invokeAttr, /*方法调用属性，扩展用，可为NULL, should be free by caller*/
			int timeout = -1, 
			int prioLevel = LEVEL_EXCHANGE_GENERAL) = 0;

	//异步RPC调用接口
        virtual int OSGI_API AsynInvoke(
			char* msgType,
			int serializeMode, /*序列化方式*/
			IMemBufReader* reqMsgContent,
			IInvokeResMsgHandler* resHandler,/*RPC消息结果回调处理接口*/
			const char* serviceName, 
			IDictionary* invokeAttr, /*方法调用属性，扩展用，可为NULL */
			int timeout = -1, 
			int prioLevel = LEVEL_EXCHANGE_GENERAL) = 0;

};



}









